package cumeo89.chii.client.entry.edit;

import com.google.gwt.xml.client.Node;

import cumeo89.chii.client.entry.EntryModel;
import cumeo89.chii.client.undo.UndoableEdit;

public class NodeValueChangingCommand implements UndoableEdit {

	private EntryModel model;
	private Node node;
	private String newValue;

	public NodeValueChangingCommand(EntryModel model, Node node, String newValue) {
		this.model = model;
		this.node = node;
		this.newValue = newValue;
	}

	public void redo() {
		swapValue();
	}

	public void undo() {
		swapValue();
	}

	private void swapValue() {
		String t = node.getNodeValue();
		model.setValue(node, newValue);
		newValue = t;
	}

}
